方式一
测试环境
Ubuntu 18.04
Nginx
准备
- 开放云服务器 443 端口
- 开放系统 443 端口
Note:https 成功后,记得把网站所有连接换成 https
1. 介绍
Let’ s Encrypt已有免费的证书可用,以后的网站估计都要上https的吧,所以把我的网站上的证书换了一下,这节主要是参考使用 acme.sh 给 Nginx 安装 Let’ s Encrypt 提供的免费 SSL 证书这篇文章,并结合自己的情况,把我的经验记录下来。
2. 安装
我们使用acme.sh来申请和管理证书,它很简单用,还能够利用crontab自动更新证书,而且是默认就有的功能。
首先安装:
1 2 3
| 1、cd 2、wget -O - https://get.acme.sh | sh 3、cd .acme.sh
|
安装完之后,可以退出登录,再重新登录,或者执行一下『source ~/.bashrc』。
之后就可以使用 acme.sh 命令了。
3. 申请证书
首先申请和下载证书:
1 2
| # -w 后面写上你自己的网站根目录 -d 自己的网站域名 ./acme.sh --issue -d www.nicefutureworld.com -w /home/wwwroot/www.nicefutureworld.com/current/public
|
申请成功后,证书会被保存在 .acme.sh 目录里面的 www.nicefutureworld.com 目录里面:

接下来我们要把证书安装到你的应用中:
1 2 3 4 5
| # ssl 文件夹不存在则先创建,需要有写的权限 ./acme.sh --installcert -d boat.rails365.net \ --keypath /home/wwwroot/www.nicefutureworld.com/ssl/www.nicefutureworld.com.key \ --fullchainpath /home/wwwroot/www.nicefutureworld.com/ssl/www.nicefutureworld.com.key.pem \ --reloadcmd "sudo lnmp reload"
|
接下来,还需要再生成一个文件,很多ssl的配置都需要它:
1
| openssl dhparam -out /home/wwwroot/www.nicefutureworld.com/ssl/dhparam.pem 2048
|
4. nginx配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| upstream boat_manager { server unix:///home/wwwroot/www.nicefutureworld.com/shared/tmp/sockets/puma.sock fail_timeout=0; }
server { listen 443 ssl; server_name www.nicefutureworld.com; ssl_certificate /home/wwwroot/www.nicefutureworld.com/ssl/www.nicefutureworld.com.key.pem; ssl_certificate_key /home/wwwroot/www.nicefutureworld.com/ssl/www.nicefutureworld.com.key; # ssl_dhparam ssl_dhparam /home/wwwroot/www.nicefutureworld.com/ssl/dhparam.pem; root /home/wwwroot/www.nicefutureworld.com/current/public keepalive_timeout 70; # 其它配置保持不变 }
server { listen 80; server_name www.nicefutureworld.com; return 301 https://www.nicefutureworld.com$request_uri; }
|
顶层的http指令那里,也需要加上这两行:
1 2 3 4
| http { ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; }
|
原文地址:https://www.qiuzhi99.com/articles/shi-yong-acme-sh-an-zhuang-let-s-encrypt-ti-gong-mian-fei-ssl-zheng-shu
方式二
准备:
先停止 Nginx
使用:https://certbot.eff.org
选择自己的环境与系统:如 Nginx Ubuntu18.04

接下来就是按文档步骤操作:操作完以后把 Nginx 配置跟上一样


